home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-01
/
tde.zip
/
TDEINPLI.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1992-07-14
|
7KB
|
199 lines
/***************************************************************************
FILENAME - TDEINPLI.CPP: class TDEInputLine
-----------------------
Class TDataEntry v1.0 - 07/14/92
--------------------------------
----------------------------------------------------------------------------
Author: Jeff Penrose * JDP Custom Software * (818) 344-7303 * CIS 71043,3727
----------------------------------------------------------------------------
A data entry class for Borland's Turbo Vision, derived from TInputLine.
Copyright Notice
================
As this material is ultimately derived from Borland source files, any of
their copyrights which MAY apply DO apply.
From the author's standpoint, you may use this material freely and,
hopefully, post any comments/corrections/enhancements to me at the above-
noted addresses. I do ask that you not distribute this material except as
originally received, including all source/documentation files in their
original form.
If you DO modify or enhance any of this code, please send any such changes
to me for incorporation into a future version. Any such enhancements will
be DONATED, without expectation of compensation or incorporation into
future versions. Again, if you distribute this code, please do so in its
original, unmodified form including all source files and documentation.
Source files included
=====================
TDE .DOC: This documentation.
TDE .MAN: How to use TDataEntry in your dialog objects
TDE .H : header file containing class declarations for classes
TDEFLAGS.H : " " " flags and command definitions
TDE .CPP: Class TDataEntry
TDEDATE .CPP: Class TDEDate
TDEPHONE.CPP: Classes TDEPhone, TDEZipCode, TDEState
TDENUMS .CPP: Class TDEInteger
TDECLUST.CPP: Non-TDataEntry classes TDEButton, TDERadioButtons, TDECheckBoxes
TDEINPLI.CPP: Non-TDataEntry class TDEInputLine
TDELIB .PRJ: Project for building library TDELIB.LIB
TDEDEMO .CPP: Demo program
TDEDEMO .PRJ: Project for building TDEDEMO.EXE
***************************************************************************/
#define Uses_TDEInputLine
#define Uses_TEvent
#define Uses_TKeys
#include <tde.h>
#ifndef __LIMITS_H // for UCHAR_MAX
#include <limits.h>
#endif
#ifndef __STRING_H
#include <string.h>
#endif
//--------------------------------------------------------------------------
//
// **** TDEInputLine::TDEInputLine
//
//--------------------------------------------------------------------------
TDEInputLine::TDEInputLine( const TRect& bounds, int aMaxLen, const char *fName ) :
TInputLine( bounds, aMaxLen ),
origData( new char[aMaxLen+1] ), fieldName( NULL )
{
eventMask |= evBroadcast;
if ( TDataEntry::globalID + 1 > UCHAR_MAX )
localID = UCHAR_MAX;
else
localID = TDataEntry::globalID++;
if ( fName && (fieldName = new char[strlen(fName) + 1]) != NULL )
strcpy(fieldName, fName);
}
//--------------------------------------------------------------------------
//
// **** TDEInputLine::~TDEInputLine
//
//--------------------------------------------------------------------------
TDEInputLine::~TDEInputLine()
{
delete origData;
delete fieldName;
}
//--------------------------------------------------------------------------
//
// **** TDEInputLine::valid()
//
//--------------------------------------------------------------------------
Boolean TDEInputLine::valid( ushort cmd )
{
if ( cmd == cmValid && origData == NULL )
return False;
return TInputLine::valid(cmd);
}
//--------------------------------------------------------------------------
//
// **** TDEInputLine::getData()
//
//--------------------------------------------------------------------------
void TDEInputLine::getData( void *rec )
{
memcpy( rec, data, strlen(data) + 1 );
}
//--------------------------------------------------------------------------
//
// **** TDEInputLine::setData()
//
//--------------------------------------------------------------------------
void TDEInputLine::setData( void *rec )
{
TInputLine::setData( rec );
if ( origData )
strcpy( origData, data );
}
//--------------------------------------------------------------------------
//
// **** TDEInputLine::handleEvent()
//
// Standard TInputLine which responds to TDataEntry::globalMode member.
//--------------------------------------------------------------------------
void TDEInputLine::handleEvent( TEvent& event )
{
if ( event.what == evBroadcast )
{
switch ( event.message.command )
{
case cmTDQueryChanged:
if ( strcmp(origData, data) != 0 )
clearEvent(event);
break;
case cmTDGotoNumber:
if ( localID == *(uchar *)event.message.infoPtr )
clearEvent(event);
break;
case cmTDResetData:
strcpy( origData, data );
break;
case cmTDGotoName:
if ( strcmp( fieldName, (char *)event.message.infoPtr ) == 0 )
clearEvent(event);
break;
default:
break;
}
return;
}
if ( event.what == evKeyDown )
{
if ( event.keyDown.keyCode == kbEnter &&
((TDataEntry::globalMode & tdgEnterIsTab) != 0) )
{
event.keyDown.keyCode = kbTab;
}
else if ( ((TDataEntry::globalMode & tdgUpDownEnable) != 0) &&
(event.keyDown.keyCode == kbUp ||
event.keyDown.keyCode == kbDown)
)
{
event.keyDown.keyCode =
(event.keyDown.keyCode == kbUp) ? kbShiftTab : kbTab;
}
else
{
ctrlToArrow(event.keyDown.keyCode);
if ( event.keyDown.charScan.charCode == kbCtrlR &&
strcmp(data, origData) != 0 )
{
strcpy( data, origData ); // Restore original data
clearEvent(event);
drawView();
}
}
}
TInputLine::handleEvent( event );
}
//--------------------------------------------------------------------------
//
// **** TDEInputLine::setState()
//
//--------------------------------------------------------------------------
void TDEInputLine::setState( ushort aState, Boolean enable )
{
TView::setState( aState, enable );
if( aState == sfSelected ||
( aState == sfActive && (state & sfSelected) != 0 ) )
if ( (TDataEntry::globalMode & tdgSelectOnFocus) )
selectAll( enable );
}